package io.renren.modules.lanling.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.lanling.entity.QuestionErrorEntity;
import io.renren.modules.lanling.service.QuestionErrorService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 错题表
 *
 * @author LANLING
 * @email lanling@gmail.com
 * @date 2018-10-24 10:12:32
 */
@RestController
@RequestMapping("lanling/questionerror")
public class QuestionErrorController {
    @Autowired
    private QuestionErrorService questionErrorService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("lanling:questionerror:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = questionErrorService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lanling:questionerror:info")
    public R info(@PathVariable("id") Integer id){
        QuestionErrorEntity questionError = questionErrorService.selectById(id);

        return R.ok().put("questionError", questionError);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("lanling:questionerror:save")
    public R save(@RequestBody QuestionErrorEntity questionError){
        questionErrorService.insert(questionError);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("lanling:questionerror:update")
    public R update(@RequestBody QuestionErrorEntity questionError){
        ValidatorUtils.validateEntity(questionError);
        questionErrorService.updateAllColumnById(questionError);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("lanling:questionerror:delete")
    public R delete(@RequestBody Integer[] ids){
        questionErrorService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
